var solution = document.getElementById("solution").value;
var datacenter = document.getElementById("dataCenter").value;
var local = document.getElementById("locale").value;
var userName = document.getElementById("userName").value;
var dbType = document.getElementById("dbType").value;
var userPass = document.getElementById("userPass").value;
var patt = document.getElementById("authPattern").value;
var hostName = document.getElementById("hostName").value;
var serverPort = document.getElementById("serverPort").value;
var requestHost = hostName + "_" + serverPort;
var appServer = document.getElementById("appServer").value;
var appSrvPort = document.getElementById("appSrvPort").value;
var currOrgId = document.getElementById("curOrgId").value;

var uiClass = document.getElementById("uiClass").value;
var uiClassParam = document.getElementById("uiClassParam").value;
var uiOprt = document.getElementById("uiOprt").value;
var openMethod = document.getElementById("openMethod").value;

if (currOrgId != ''){
    solution += ';'+ currOrgId;
}

if(appServer == null || appServer == "") {
	appServer = "tcp://" + hostName;
}
if(appSrvPort != "") {
	appServer += ":" + appSrvPort ;
}

	var totalFile ;
function eas::onload() {
	//alert("connecting..");
	//eas.Connect("localhost_6888");
}

function connect(){
    if (!eas.IsConnected) {
		var res = eas.Connect(requestHost);		
		return res;
    }
}

function leaveCtrl() {
	if(eas.IsConnected)
	eas.SendMessage(5,"exit");	
}

function eas::OnMessage(id,value) {
	eas.text = "" + id + ": " + value;
	if(id=='8') {
		document.all("fileupdate").innerHTML="<span class='processbar_label'>"+value + "</span>";
	}
	else if(id=='10') {
		if(value.indexOf('T')>=0) {
			totalFile = value.substring(1,value.length);
                	document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ "0/"+totalFile + "</span>";
		  	process_messageId.innerText="updating files...";
		}
		else {
			document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ value+"/"+totalFile + "</span>";
			if(parseInt(value)>=parseInt(totalFile)||value=="") {
				document.all("fileprogess").innerHTML="<span class='processbar_label'>"+ "" + "</span>";;
				process_messageId.innerText="init eas application...";
			}
		}
	}
	else if(id=='9') {	//start success	
        //setAppletState('started');
        //loginEas();
        setTimeout("loginEas()",   100); 
	} else if(id=='12') {
	    //apploader =true;
		//setIsInitEasFrame('0');
		//setLogined(false);
		//setNeedLogin('true');
	} else if(value.indexOf("JSParameterProviderClassName,")<0 && (id!="5")&& (id!="1") &&(id!="0")&&(value.indexOf("com.kingdee")<0)){
		//alert("id:"+id+"value:"+value)
	    eval(value+";");
	}
	else {
	}
}
function sendMessage(id ,value) {
	//alert(value);
	if(!eas.IsConnected) {
		 eas.Connect(requestHost);
	}	
    var result = eas.SendMessage(id,value);	
	//alert("send complete!");
}
function postMessage(id ,value) {
	eas.postMessage(id ,value);
}

function invokeFunction(){
	//alert(uiClass+","+uiClassParam+","+uiOprt+","+openMethod);
    sendMessage('3',uiClass+","+uiClassParam+","+uiOprt+","+openMethod);
}

function loginEas() {
	//alert("login...");
    loginEasClient(solution, datacenter, local, dbType, userName, userPass, patt);
}

function loginEasClient(solution,dccenter,locale,dbtype,username,password,authPattern){

	//login Eas Client
	var keys = new Array();
 	var values= new Array();
	var paramCount = -1 ;
        paramCount++;
	keys[paramCount] = "type";
	values[paramCount] = "new" ;

	paramCount++;
	keys[paramCount] = "JSParameterProviderClassName";
	values[paramCount] = "com.kingdee.eas.cp.eip.apploader.LoginJSParameterProvider" ;
	paramCount++;
	keys[paramCount] = "solution";
	values[paramCount] = (solution=="null"?"":solution) ;
	paramCount++;
	keys[paramCount] = "dccenter";
	values[paramCount] = (dccenter=="null"?"":dccenter) ;
	paramCount++;
	keys[paramCount] = "locale";
	values[paramCount] = (locale=="null"?"":locale) ;
	paramCount++;
	keys[paramCount] = "dbtype";
	values[paramCount] = new String(dbtype=="null"?0:dbtype) ;
	paramCount++;
	keys[paramCount] = "username";
	values[paramCount] = (username=="null"?"":username) ;
	paramCount++;
	keys[paramCount] = "password";
	values[paramCount] = (password=="null"?"":password) ;
	paramCount++;
	keys[paramCount] = "authPattern";
	values[paramCount] = (authPattern =="null"?"":authPattern) ;

	paramCount++;
	keys[paramCount] = "returnEvent";
	var returnEventStr = "returnValuePerformedForLogin" ;
	values[paramCount] =  returnEventStr;
	
  	invokeEasBiz(keys.join(","),values.join(","),returnEventStr);
}

function invokeEasBiz(keyStr,valStr,returnEventStr) {
	sendMessage("2",keyStr+";:;"+valStr);
}

function returnEventPerformed(event,returnValue) {
	//alert("show ui...");
	//invokeFunction('com.kingdee.eas.basedata.assistant.client.CurrencyListUI', 'aa', '0', '0');
}

function returnValuePerformedForLogin() {
}

function pageOnload() {
	connect();
	sendMessage(1, requestHost + "," + appServer);
	setTimeout("loginEas()",   100); 
}